package com.vtuzx.kingdee.xqc_api.web;

import com.vtuzx.core.VtuzxException;
import com.vtuzx.core.bean.dto.VtuzxMap;
import com.vtuzx.core.bean.dto.VtuzxToken;
import com.vtuzx.core.constant.IVtuzxConst;
import com.vtuzx.core.utils.VtuzxUtil;
import com.vtuzx.kingdee.xqc_api.service.IXqcTrayService;
import com.vtuzx.web.constant.ApiType;
import com.vtuzx.web.validator.VtuzxValidator;
import com.vtuzx.web.web.VtuzxApi;
import com.vtuzx.web.web.VtuzxControlParam;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 调拨
 */
@RequestMapping("/${vtuzx.fast.api.path}/${vtuzx.fast.api.version}/tray")
@RestController
public class XqcTrayController {

    @Autowired
    IXqcTrayService trayService;


    /**
     * 获取托盘信息列表
     */
    @PostMapping("/get_tray_list")
    @VtuzxApi
    public Object getTrayList(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String name = VtuzxUtil.getString(token, "name");
        return trayService.getTrayList(_userId, name, param);

    }

    /**
     * 扫描托盘
     */
    @PostMapping("/scan_tray")
    @VtuzxApi
    public Object scanTray(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String name = VtuzxUtil.getString(token, "name");
        return trayService.scanTray(_userId, name, param);

    }

    /**
     * 托盘管理获取物料信息（箱号）
     */
    @PostMapping("/get_material_boxNo_tray")
    @VtuzxApi
    public Object getMaterialBoxNoTray(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String name = VtuzxUtil.getString(token, "name");
        return trayService.getMaterialBoxNoTray(_userId, name, param);
    }

    /**
     * 托盘管理获取物料信息（rfid）
     */
    @PostMapping("/get_material_rfid_tray")
    @VtuzxApi
    public Object getMaterialRfidTray(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String name = VtuzxUtil.getString(token, "name");
        return trayService.getMaterialRfidTray(_userId, name, param);
    }


    /**
     * 托盘管理添加箱子
     */
    @PostMapping("/add_tray_box")
    @VtuzxApi
    public Object addTrayBox(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String name = VtuzxUtil.getString(token, "name");
        trayService.addTrayBox(_userId, name, param);
        return null;
    }


    /**
     * 托盘管理创建订单
     */
    @PostMapping("/create_tray_bill")
    @VtuzxApi
    public Object createTrayBill(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String name = VtuzxUtil.getString(token, "name");
        trayService.createTrayBill(_userId, name, param);
        return null;
    }


    /**
     * 获取临时物料列表
     */
    @PostMapping("/get_user_material_list_tray")
    @VtuzxApi
    public Object getUserMaterialListTray(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String name = VtuzxUtil.getString(token, "name");
        return trayService.getUserMaterialListTray(_userId, name, param);
    }

    /**
     * 获取临时箱子列表
     */
    @PostMapping("/get_user_box_list_tray")
    @VtuzxApi
    public Object getUserBoxListTray(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String name = VtuzxUtil.getString(token, "name");
        return trayService.getUserBoxListTray(_userId, name, param);
    }

    /**
     * 托盘删除物料
     */
    @PostMapping("/delete_user_material_tray")
    @VtuzxApi
    public Object deleteUserMaterialTray(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String name = VtuzxUtil.getString(token, "name");
        trayService.deleteUserMaterialTray(_userId, name, param);
        return null;
    }


    /**
     * 托盘删除箱子
     */
    @PostMapping("/delete_user_box_tray")
    @VtuzxApi
    public Object deleteUserBoxTray(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String name = VtuzxUtil.getString(token, "name");
        trayService.deleteUserBoxTray(_userId, name, param);
        return null;
    }

    /**
     * 查询调拨履历列表
     */
    @PostMapping("/get_tray_bind_list")
    @VtuzxApi
    public Object getTrayBindList(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String name = VtuzxUtil.getString(token, "name");
        return trayService.getTrayBindList(_userId, name, param);
    }

    /**
     * 查询调拨履历详细
     */
    @PostMapping("/get_tray_bind_detail")
    @VtuzxApi
    public Object getTrayBindDetail(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String name = VtuzxUtil.getString(token, "name");
        return trayService.getTrayBindDetail(_userId, name, param);
    }

    /**
     * 查询调拨履历详细箱号
     */
    @PostMapping("/get_tray_bind_detail_box")
    @VtuzxApi
    public Object getTrayBindDetailBox(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String name = VtuzxUtil.getString(token, "name");
        return trayService.getTrayBindDetailBox(_userId, name, param);

    }


    /**
     * 选择行下载托盘信息
     */
    @PostMapping("/download_tray_list")
    @VtuzxApi(type = ApiType.Download)
    public Object downloadTrayList(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws Exception {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        return trayService.downloadTrayList(_userId, param);
    }



    /**
     * 托盘盘点
     */
    @PostMapping("/tray_inventory")
    @VtuzxApi
    public Object trayInventory(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String name = VtuzxUtil.getString(token, "name");
        return trayService.trayInventory(_userId, name, param);

    }



    /**
     * 获取托盘盘点列表
     */
    @PostMapping("/get_tray_inventory_list")
    @VtuzxApi
    public Object getTrayInventoryList(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String name = VtuzxUtil.getString(token, "name");
        return trayService.getTrayInventoryList(_userId, name, param);

    }


    /**
     * 获取托盘盘点详细
     */
    @PostMapping("/get_tray_inventory_detail")
    @VtuzxApi
    public Object getTrayInventoryDetail(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String name = VtuzxUtil.getString(token, "name");
        return trayService.getTrayInventoryDetail(_userId, name, param);

    }

    /**
     * 下载托盘盘点
     */
    @PostMapping("/download_tray_inventory_list")
    @VtuzxApi(type = ApiType.Download)
    public Object downloadTrayInventoryList(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws Exception {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        return trayService.downloadTrayInventoryList(_userId, param);
    }

}
